<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/view/inc/sys.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>${projectName}-编辑应用</title>
<jsp:include page="/WEB-INF/view/inc/css.jsp"></jsp:include>
</head>
<body>
	<jsp:include page="/WEB-INF/view/inc/header.jsp"></jsp:include>
	<div class="container">
		<jsp:include page="/WEB-INF/view/admin/comm/left.jsp">
			<jsp:param name="first" value="app"/>
			<jsp:param name="second" value="appInfoManager"/>
		</jsp:include>
		<div class="c-right">
			<div class="${bodyMainClass}">
				<div class="panel-heading panel-heading-tool">
					<div class="row">
						<div class="col-sm-5 title">应用管理 / <b>应用列表-(${appInfo.name})</b></div>
						<div class="col-sm-7 text-right">
							<div class="btn-group">
						  		<a href="${webroot}/appInfo/f-view/manager" class="btn btn-default btn-sm">返回</a>
						  		<a href="javascript:location.reload()" class="btn btn-default btn-sm">刷新</a>
							</div>
						</div>
					</div>
				</div>
				<div class="panel-body">
					<ul class="nav nav-tabs">
				    	<li <c:if test="${param.tab==null || param.tab=='app'}"> class="active"</c:if>><a href="#appPanel" data-toggle="tab">应用详情</a></li>
				    	<li <c:if test="${param.tab=='prj'}"> class="active"</c:if>><a href="#prjPanel" onclick="prjInfo.init()" data-toggle="tab">服务列表</a></li>
				    	<li <c:if test="${param.tab=='user'}"> class="active"</c:if>><a href="#userPanel" onclick="userInfo.init()" data-toggle="tab">成员管理</a></li>
				    	<li <c:if test="${param.tab=='ant'}"> class="active"</c:if>><a href="#antPanel" onclick="antInfo.init()" data-toggle="tab">原型管理</a></li>
				    	<li <c:if test="${param.tab=='apiAutoTest'}"> class="active"</c:if>><a href="#apiAutoTestPanel" onclick="apiAutoTestInfo.init()" data-toggle="tab">API自动化测试</a></li>
				  	</ul>
				  	<div class="tab-content">
					  	<input type="hidden" id="aiId" value="${param.aiId}"/>
				  		<div class="tab-pane <c:if test="${param.tab==null || param.tab=='app'}">active</c:if>" id="appPanel">
				  			<div class="enter-panel">
				  			<table class="table-dtl">
				  				<tr>
				  					<td class="title">编码 <span class="text-danger">*</span></td>
				  					<td><input type="text" class="form-control" id="code" placeholder="用户编码" value="${appInfo.code}"></td>
				  				</tr>
				  				<tr>
				  					<td class="title">名称 <span class="text-danger">*</span></td>
				  					<td><input type="text" class="form-control" id="name" placeholder="名称" value="${appInfo.name}"></td>
				  				</tr>
				  				<tr>
				  					<td class="title">备注</td>
				  					<td><input type="text" class="form-control" id="remark" placeholder="备注" value="${appInfo.remark}"></td>
				  				</tr>
				  				<my:auth mid="appInfoManagerUpd">
				  				<tr>
				  					<td></td>
				  					<td><button type="button" id="saveBtn" class="btn btn-success enter-fn">保存</button>
				  						<span id="saveMsg" class="label label-danger"></span>
				  					</td>
				  				</tr>
				  				</my:auth>
				  			</table>
				  			</div>
				  		</div>
				    	<div class="tab-pane <c:if test="${param.tab=='prj'}">active</c:if>" id="prjPanel">
				    		<div class="table-tool-panel">
								<div class="row">
									<div class="col-sm-9 enter-panel">
										<input type="text" class="form-control input-sm w-120" id="prjName" placeholder="服务名称" value="" data-provide="typeahead" autocomplete="off"/>
										<input type="hidden" id="prjId"/>
									  	<button type="button" class="btn btn-sm btn-danger enter-fn" onclick="prjInfo.add()">关联服务</button>
									</div>
									<div class="col-sm-3 text-right">
									</div>
								</div>
						  	</div>
							<div id="prjInfoPanel" class="table-panel"></div>
							<div id="prjInfoPage" class="table-page-panel"></div>
				    	</div>
				    	<div class="tab-pane <c:if test="${param.tab=='user'}">active</c:if>" id="userPanel">
				    		<div class="table-tool-panel">
								<div class="row">
									<div class="col-sm-9 enter-panel">
										<input type="text" class="form-control input-sm w-120" id="userName" placeholder="用户名称" value="" data-provide="typeahead" autocomplete="off"/>
										<input type="hidden" id="userId"/>
									  	<button type="button" class="btn btn-sm btn-danger enter-fn" onclick="userInfo.add()">关联用户</button>
									</div>
									<div class="col-sm-3 text-right">
									</div>
								</div>
						  	</div>
							<div id="userInfoPanel" class="table-panel"></div>
							<div id="userInfoPage" class="table-page-panel"></div>
				    	</div>
				    	<div class="tab-pane <c:if test="${param.tab=='ant'}">active</c:if>" id="antPanel">
				    		<div class="layout">
						  		<div class="left" style="width: 25%;">
						  			<div class="table-tool-panel">
										<div class="row">
											<div class="col-sm-11 enter-panel">
												<input type="text" class="form-control input-sm w-120" id="antName" placeholder="原型名称" value=""/>
											  	<button type="button" class="btn btn-sm btn-default enter-fn" onclick="antInfo.loadInfo(1)">查询</button>
											  	<a href="javascript:;" class="btn btn-danger btn-sm" onclick="antInfo.edit()">新增</a>
											</div>
											<div class="col-sm-1 text-right">
											  	<div class="btn-group">
											  		
											  	</div>
											</div>
										</div>
								  	</div>
									<div id="antInfoPanel" class="table-panel" style="min-height: calc(100% - 50px);height: auto;border-bottom: 1px solid #e1e6eb;"></div>
									<!-- <div id="antInfoPage" class="table-page-panel"></div> -->
						  		</div>
						  		<div class="right" style="width: 75%;">
						  			<div class="table-tool-panel">
										<div class="row">
											<div class="col-sm-6" id="antDtlLeftPanel">
												<span>请选择功能进行查看~</span>
											</div>
											<div class="col-sm-6 text-right">
												<div class="btn-group">
											  		<a href="javascript:;" class="btn btn-default btn-sm" onclick="antDtlInfo.edit()">修改</a>
											  	</div>
											</div>
										</div>
								  	</div>
									<div id="antDtlInfoPanel" class="table-panel" style="min-height: calc(100% - 50px);height: auto;border-bottom: 1px solid #e1e6eb;"></div>
									<!-- <div id="antDtlInfoPage" class="table-page-panel"></div> -->
						  		</div>
						  	</div>
				    	</div>
				    	<div class="tab-pane <c:if test="${param.tab=='apiAutoTest'}">active</c:if>" id="apiAutoTestPanel">
						  	<div class="layout">
						  		<div class="left" style="width: 30%;">
						  			<div class="table-tool-panel">
										<div class="row">
											<div class="col-sm-11 enter-panel">
												<input type="text" class="form-control input-sm w-120" id="aaTestName" placeholder="版本名称" value=""/>
											  	<button type="button" class="btn btn-sm btn-default enter-fn" onclick="apiAutoTestInfo.loadInfo(1)">查询</button>
											  	<my:auth mid="appInfoManagerApiAdd"><a href="javascript:;" class="btn btn-success btn-sm" onclick="apiAutoTestInfo.edit()">新增</a></my:auth>
											</div>
											<div class="col-sm-1 text-right">
											  	<div class="btn-group">
											  		
											  	</div>
											</div>
										</div>
								  	</div>
									<div id="apiAutoTestInfoPanel" class="table-panel"></div>
									<div id="apiAutoTestInfoPage" class="table-page-panel"></div>
						  		</div>
						  		<div class="right" style="width: 70%;">
						  			<div class="table-tool-panel">
										<div class="row">
											<div class="col-sm-8 enter-panel">
												<input type="text" class="form-control input-sm w-120" id="aaTestDtlPath" placeholder="接口地址" value=""/>
											  	<button type="button" class="btn btn-sm btn-default enter-fn" onclick="apiAutoTestDtlInfo.loadInfo(1)">查询</button>
											  	<a href="javascript:;" class="btn btn-danger btn-sm" onclick="apiAutoTestDtlInfo.auto()">自动测试</a>
											  	<a href="javascript:;" class="btn btn-danger btn-sm" onclick="apiAutoTestDtlInfo.lookReport()">查看报告</a>
											</div>
											<div class="col-sm-4 text-right">
											  	<div class="btn-group">
											  		<my:auth mid="appInfoManagerApiDtlAdd"><a href="javascript:;" class="btn btn-success btn-sm" onclick="apiAutoTestDtlInfo.edit()">+接口</a></my:auth>
											  	</div>
											</div>
										</div>
								  	</div>
									<div id="apiAutoTestDtlInfoPanel" class="table-panel"></div>
									<div id="apiAutoTestDtlInfoPage" class="table-page-panel"></div>
						  		</div>
						  	</div>
				    	</div>
				    	
				  	</div>
				  	
				</div>
			</div>
		</div>
		<br clear="all">
	</div>
	<jsp:include page="/WEB-INF/view/inc/js.jsp"></jsp:include>
	<jsp:include page="/WEB-INF/view/inc/utils/page.jsp"></jsp:include>
<script type="text/javascript">
var antDtlInfo = {
		edit: function() {
			if (!antDtlInfo.aaId) {
				message('请先选择对应的功能');
				return;
			}
			dialog({
				title: '编辑',
				url: webroot + '/appAnt/f-view/edit?aiId=${param.aiId}&aaId='+antDtlInfo.aaId,
				type: 'iframe',
				width: 520,
				height: 400
			});
		}
};
var antInfo = {
		init: function() {
			antInfo.loadInfo();
		},
		loadInfo: function() {
			var antInfoPanel = $('#antInfoPanel').empty();
			JUtil.ajax({
				url: '${webroot}/appAnt/f-json/findTree',
				data: {
					aiId: '${param.aiId}',
					name: $('#antName').val()
				},
				success : function(json) {
					if (json.code === 0) {
						var content = ['<div class="tree-info">'];
						$.each(json.body, function(i, obj) {
							content.push('<div class="tree-item"><span onclick="antInfo.look(this,\'',obj.aaId,'\')"><span class="structure">|-</span>',obj.name,'</span>&nbsp;&nbsp;',
									'<span class="dropdown opt-more">',
									'	<a class="text-muted dropdown-toggle" href="javascript:;" data-toggle="dropdown"><span class="glyphicon glyphicon-cog"></span></a>',
									'	<ul class="dropdown-menu" role="menu">',
									'	<li role="presentation"><a href="javascript:antInfo.edit(\'',obj.aaId,'\')">修改</a></li>',
									'	<li role="presentation"><a href="javascript:antInfo.del(\'',obj.aaId,'\')">删除</a></li>',
									'	<li role="presentation"><a href="javascript:antInfo.edit(\'\',\'',obj.aaId,'\')" title="在当前功能基础上添加下级功能">+下级功能</a></li>',
									'	</ul>',
									'</span>',
								'</div>');
							$.each(obj.cldList, function(ii, obj1) {
								content.push('<div class="tree-item"><span onclick="antInfo.look(this,\'',obj1.aaId,'\')"><span class="structure">&nbsp;&nbsp;&nbsp;|--</span>',obj1.name,'</span>&nbsp;&nbsp;',
										'<span class="dropdown opt-more">',
										'	<a class="text-muted dropdown-toggle" href="javascript:;" data-toggle="dropdown"><span class="glyphicon glyphicon-cog"></span></a>',
										'	<ul class="dropdown-menu" role="menu">',
										'	<li role="presentation"><a href="javascript:antInfo.edit(\'',obj1.aaId,'\')">修改</a></li>',
										'	<li role="presentation"><a href="javascript:antInfo.del(\'',obj1.aaId,'\')">删除</a></li>',
										'	<li role="presentation"><a href="javascript:antInfo.edit(\'\',\'',obj1.aaId,'\')" title="在当前功能基础上添加下级功能">+下级功能</a></li>',
										'	</ul>',
										'</span>');

								content.push('</div>');
								
								$.each(obj1.cldList, function(iii, obj2) {
									content.push('<div class="tree-item"><span onclick="antInfo.look(this,\'',obj2.aaId,'\')"><span class="structure">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|--</span>',obj2.name,'</span>&nbsp;&nbsp;',
											'<span class="dropdown opt-more">',
											'	<a class="text-muted dropdown-toggle" href="javascript:;" data-toggle="dropdown"><span class="glyphicon glyphicon-cog"></span></a>',
											'	<ul class="dropdown-menu" role="menu">',
											'	<li role="presentation"><a href="javascript:antInfo.edit(\'',obj2.aaId,'\')">修改</a></li>',
											'	<li role="presentation"><a href="javascript:antInfo.del(\'',obj2.aaId,'\')">删除</a></li>',
											'	</ul>',
											'</span>');
									
									content.push('</div>');
								});
								
							});
						});
						content.push('</div>');
						antInfoPanel.append(content.join(''));
						JUtil.sys.initOptMore();
					}
					else if (json.code === -1)
						message(JUtil.msg.ajaxErr);
					else
						message(json.message);
				}
			});
		},
		look: function(_this, aaId) {
			antDtlInfo.aaId = aaId;
			$('.tree-item').each(function(i, item) {
				$(item).attr('class', 'tree-item');
			});
			$(_this).parent().attr('class', 'tree-item tree-item-success');
			JUtil.ajax({
				url: '${webroot}/appAnt/f-json/get',
				data: {
					aaId: aaId
				},
				success : function(json) {
					if (json.code === 0) {
						var obj = json.body;
						$('#antDtlLeftPanel').empty().append('<span class="text-muted">功能名称：</span>' + obj.name);
						var antDtlInfoPanel = $('#antDtlInfoPanel').empty();
						var content = ['<div>'];
						var type = obj.type;
						if (type == 10 && obj.typeValue) {
							content.push('<iframe src="',obj.typeValue,'" style="width: 100%;height:300px;border: 0;"/>');
							content.push('<div style="padding: 10px;"><span class="text-muted">原型地址：</span><a href="',obj.typeValue,'" target="_blank"><small>',obj.typeValue,'</small></a></div>');
						} else if (type == 20 && obj.typeValue) {
							content.push('<img id="filesLoading" alt="原型图" style="width: 100%;height:auto;border: 0;" src="${webroot}/sysFile/f-view/preview.shtml?url=',obj.typeValue,'"/>');
							content.push('<div style="padding: 10px;"><span class="text-muted">图片地址：</span><a href="${webroot}/sysFile/f-view/preview.shtml?url=',obj.typeValue,'" target="_blank"><small>查看原图</small></a></div>');
						} else {
							content.push('<div style="padding: 10px;"><span class="text-muted">未选择功能原型的展示类型，不展示信息。</span></div>');
						}
						
						content.push('<table class="table table-striped table-hover" style="border-left: 0;border-right: 0;">',
								'<thead>',
								'<tr class="info">',
					            '	<th width="200">服务</th>',
					            '	<th>接口名称或地址</th>',
								'</tr>',
					            '</thead>',
					            '<tbody>');
						if (obj.apiInfo) {
							var apiInfo = $.parseJSON(obj.apiInfo);
							$.each(apiInfo, function(i, item) {
								var url = '';
								if (item.prjName) {
									url = '${webroot}/prjApi/f-view/dtl.shtml?prjId='+item.prjId+'&path='+item.path;
								} else {
									url = item.path;
								}
								content.push('<tr>',
									'<td>',item.prjName,'</td>',
									'<td><a class="text-success" href="',url,'" target="_blank">',item.pathName,'</a></td>',
									'</tr>');
							});
						} else {
							content.push('<tr>',
									'<td colspan="2">无接口信息</td>',
									'</tr>');
						}
						
						content.push('</tbody></table>');
						
						content.push('<hr/>',
								'<div style="padding: 10px;"><span class="text-muted">备注：</span>',obj.remark,'</div>');
						content.push('<br/></div>');
						antDtlInfoPanel.append(content.join(''));
					}
					else if (json.code === -1)
						message(JUtil.msg.ajaxErr);
					else
						message(json.message);
				}
			});
		},
		edit : function(id, parentAaId) {
			dialog({
				title: '编辑',
				url: webroot + '/appAnt/f-view/edit?aiId=${param.aiId}&aaId='+(id?id:'')+'&parentAaId='+(parentAaId?parentAaId:'0'),
				type: 'iframe',
				width: 520,
				height: 400
			});
		},
		del: function(aaId) {
			if(confirm('您确定要删除该记录吗?')) {
				JUtil.ajax({
					url: '${webroot}/appAnt/f-json/delete',
					data: {
						aaId: aaId
					},
					success : function(json) {
						if (json.code === 0) {
							setTimeout(function() {
								antInfo.loadInfo();
							}, 800);
						}
						else if (json.code === -1)
							message(JUtil.msg.ajaxErr);
						else
							message(json.message);
					}
				});
			}
		}
};
var apiAutoTestInfoPage = undefined;
var apiAutoTestInfo = {
		init: function() {
			apiAutoTestInfo.loadInfo(1);
		},
		loadInfo : function(page) {
			if(!apiAutoTestInfoPage) {
				apiAutoTestInfoPage = new Page('apiAutoTestInfoPage', apiAutoTestInfo.loadInfo, 'apiAutoTestInfoPanel', 'apiAutoTestInfoPage');
				apiAutoTestInfoPage.beginString = ['<table class="table table-striped table-hover"><thead><tr class="info">',
				                         '<th>版本名称</th>',
				                         '<th width="80">操作</th>',
				                         '</tr></thead><tbody>'].join('');
				apiAutoTestInfoPage.endString = '</tbody></table>';
			}
			if(page != undefined) {
				apiAutoTestInfoPage.page = page;
				apiAutoTestDtlInfo.aatId = undefined;
			}

			JUtil.ajax({
				url : '${webroot}/appApiTest/f-json/pageQuery',
				data : { page:apiAutoTestInfoPage.page, size:apiAutoTestInfoPage.size, aiId: $('#aiId').val() },
				beforeSend: function(){ apiAutoTestInfoPage.beforeSend('加载信息中...'); },
				error : function(json){ apiAutoTestInfoPage.error('加载信息出错了!'); },
				success : function(json){
					if(json.code === 0) {
						function getResult(obj) {
							var trClass = '';
							if(apiAutoTestDtlInfo.aatId === undefined) {
								//为第一次进来，默认加载发布的项
								apiAutoTestDtlInfo.aatId = obj.aatId;
								apiAutoTestDtlInfo.loadInfo(1);
								trClass = 'success';
							}
							return ['<tr class="',trClass,'" onclick="apiAutoTestInfo.toApi(this,\'',obj.aatId,'\')">',
							    	'<td>',obj.name,'</td>',
							    	'<td><my:auth mid="appInfoManagerApiUpd"><a class="glyphicon glyphicon-edit text-success" href="javascript:apiAutoTestInfo.edit(\'',obj.aatId,'\')" title="修改"></a></my:auth>',
							    	'<my:auth mid="appInfoManagerApiDel">&nbsp; <a class="glyphicon glyphicon-remove text-success" href="javascript:apiAutoTestInfo.del(\'',obj.aatId,'\')" title="删除"></a></my:auth>',
							    	'<my:auth mid="appInfoManagerApiAdd">&nbsp; <a class="text-success" href="javascript:apiAutoTestInfo.copy(\'',obj.aatId,'\',\'',obj.name,'\')" title="复制版本">复制</a></my:auth>',
							    	'</td>',
								'</tr>'].join('');
						}
						apiAutoTestInfoPage.operate(json.body, { resultFn:getResult, dataNull:'没有记录噢' });
					}
					else alert(JUtil.msg.ajaxErr);
				}
			});
		},
		edit : function(id) {
			dialog({
				title: '编辑',
				url: webroot + '/appApiTest/f-view/edit?aiId=${param.aiId}&aatId='+(id?id:''),
				type: 'iframe',
				width: 420,
				height: 320
			});
		},
		copy : function(copyAatId, copyAatName) {
			dialog({
				title: '复制',
				url: webroot + '/appApiTest/f-view/edit?aiId=${param.aiId}&copyAatId='+copyAatId+'&copyAatName='+copyAatName,
				type: 'iframe',
				width: 420,
				height: 320
			});
		},
		toApi : function(_this, aatId) {
			var tr = $(_this);
			tr.parent().find('tr').each(function(i, obj) {
				$(obj).removeClass('success');
			});
			tr.addClass('success');
			apiAutoTestDtlInfo.aatId = aatId;
			apiAutoTestDtlInfo.loadInfo(1);
		},
		del: function(aatId) {
			if(confirm('您确定要删除该记录吗?')) {
				JUtil.ajax({
					url: '${webroot}/appApiTest/f-json/delete',
					data: {
						aatId: aatId
					},
					success : function(json) {
						if (json.code === 0) {
							setTimeout(function() {
								apiAutoTestInfo.loadInfo();
							}, 800);
						}
						else if (json.code === -1)
							message(JUtil.msg.ajaxErr);
						else
							message(json.message);
					}
				});
			}
		}
};
var apiAutoTestDtlInfoPage = undefined;
var apiAutoTestDtlInfo = {
		loadInfo: function(page) {
			if(!apiAutoTestDtlInfoPage) {
				apiAutoTestDtlInfoPage = new Page('apiAutoTestDtlInfoPage', apiAutoTestDtlInfo.loadInfo, 'apiAutoTestDtlInfoPanel', 'apiAutoTestDtlInfoPage');
				apiAutoTestDtlInfoPage.beginString = ['<table class="table table-striped table-hover"><thead><tr class="info">',
					                     '<th>执行号</th>',
					                     '<th>服务</th>',
					                     '<th>接口信息</th>',
				                         '<th>测试时间</th>',
				                         '<th>结果</th>',
				                         '<th width="80">操作</th>',
				                         '</tr></thead><tbody>'].join('');
				apiAutoTestDtlInfoPage.endString = '</tbody></table>';
			}
			if(page != undefined)
				apiAutoTestDtlInfoPage.page = page;

			JUtil.ajax({
				url : '${webroot}/appApiTest/f-json/pageQueryDtl',
				data : { page:apiAutoTestDtlInfoPage.page, size:apiAutoTestDtlInfoPage.size, aatId: apiAutoTestDtlInfo.aatId, path: $('#aaTestDtlPath').val() },
				beforeSend: function(){ apiAutoTestDtlInfoPage.beforeSend('加载信息中...'); },
				error : function(json){ apiAutoTestDtlInfoPage.error('加载信息出错了!'); },
				success : function(json){
					if(json.code === 0) {
						function getResult(obj) {
							return ['<tr>',
						    		'<td>',obj.orderby,'</td>',
							    	'<td>',obj.prjName,'</td>',
							    	'<td>',obj.pathName,'(',obj.path,')','</td>',
							    	'<td>',obj.testTime,'</td>',
							    	'<td>',obj.statusMsg,'</td>',
							    	'<td><a class="text-success" href="javascript:apiAutoTestDtlInfo.test(\'',obj.aatdId,'\')" title="测试">测试</a>',
							    	'&nbsp; <span class="dropdown opt-more">',
									'<a class="text-success dropdown-toggle" href="javascript:;" data-toggle="dropdown">更多...</a>',
									'<ul class="dropdown-menu right" role="menu">',
									'<my:auth mid="appInfoManagerApiDtlUpd"><li role="presentation"><a href="javascript:apiAutoTestDtlInfo.edit(\'',obj.aatdId,'\')">修改</a></li></my:auth>',
									'<my:auth mid="appInfoManagerApiDtlDel"><li role="presentation"><a href="javascript:apiAutoTestDtlInfo.del(\'',obj.aatdId,'\')">删除</a></li></my:auth>',
									'<li role="presentation"><a href="javascript:apiAutoTestDtlInfo.lastLog(\'',obj.aatdId,'\')" title="当前的测试结果">当前结果</a></li>',
									'</ul>',
									'</span>',
							    	'</td>',
								'</tr>'].join('');
						}
						apiAutoTestDtlInfoPage.operate(json.body, { resultFn:getResult, dataNull:'没有记录噢' });
						JUtil.sys.initOptMore();
					}
					else alert(JUtil.msg.ajaxErr);
				}
			});
		},
		edit : function(id) {
			dialog({
				title: '编辑',
				url: webroot + '/appApiTest/f-view/editDtl?aiId=${param.aiId}&aatId='+apiAutoTestDtlInfo.aatId+'&aatdId='+(id?id:''),
				type: 'iframe',
				width: 620,
				height: 500
			});
		},
		lookReport: function() {
			dialog({
				title: '查看报告',
				url: webroot + '/appApiTest/f-view/lookReport?aatId='+apiAutoTestDtlInfo.aatId,
				type: 'iframe',
				width: 620,
				height: 500
			});
		},
		lastLog: function(aatdId) {
			dialog({
				title: '对比结果',
				url: webroot + '/appApiTest/f-view/getLastLog?aatdId='+aatdId,
				type: 'iframe',
				width: 620,
				height: 520
			});
		},
		test: function(aatdId) {
			JUtil.ajax({
				url: '${webroot}/appApiTest/f-json/test',
				data: {
					aatdId: aatdId
				},
				success : function(json) {
					if (json.code === 0) {
						setTimeout(function() {
							apiAutoTestDtlInfo.loadInfo();
							// 打开查看结果页面
							dialog({
								title: '对比结果',
								url: webroot + '/appApiTest/f-view/getLastLog?aatdId='+aatdId,
								type: 'iframe',
								width: 620,
								height: 520
							});
						}, 800);
					}
					else if (json.code === -1)
						message(JUtil.msg.ajaxErr);
					else
						message(json.message);
				}
			});
		},
		auto: function(aatId) {
			JUtil.ajax({
				url: '${webroot}/appApiTest/f-json/testAll',
				data: {
					aatId: apiAutoTestDtlInfo.aatId
				},
				success : function(json) {
					if (json.code === 0) {
						message(json.message);
						setTimeout(function() {
							apiAutoTestDtlInfo.loadInfo();
						}, 800);
					}
					else if (json.code === -1)
						message(JUtil.msg.ajaxErr);
					else
						message(json.message);
				}
			});
		},
		del: function(aatdId) {
			if(confirm('您确定要删除该记录吗?')) {
				JUtil.ajax({
					url: '${webroot}/appApiTest/f-json/deleteDtl',
					data: {
						aatdId: aatdId
					},
					success : function(json) {
						if (json.code === 0) {
							setTimeout(function() {
								apiAutoTestDtlInfo.loadInfo();
							}, 800);
						}
						else if (json.code === -1)
							message(JUtil.msg.ajaxErr);
						else
							message(json.message);
					}
				});
			}
		}
};

var prjInfoPage = undefined;
var prjInfo = {
		init: function() {
			prjInfo.loadInfo(1);
		},
		loadInfo : function(page) {
			if(!prjInfoPage) {
				prjInfoPage = new Page('prjInfoPage', prjInfo.loadInfo, 'prjInfoPanel', 'prjInfoPage');
				prjInfoPage.beginString = ['<table class="table table-striped table-hover"><thead><tr class="info">',
				                         '<th>服务编码</th>',
				                         '<th>服务名称</th>',
				                         '<th>关联人</th>',
				                         '<th width="150">关联时间</th>',
				                         '<th width="80">操作</th>',
				                         '</tr></thead><tbody>'].join('');
				prjInfoPage.endString = '</tbody></table>';
			}
			if(page != undefined)
				prjInfoPage.page = page;

			JUtil.ajax({
				url : '${webroot}/appInfo/f-json/pageQueryPrj',
				data : { page:prjInfoPage.page, size:prjInfoPage.size, aiId: $('#aiId').val() },
				beforeSend: function(){ prjInfoPage.beforeSend('加载信息中...'); },
				error : function(json){ prjInfoPage.error('加载信息出错了!'); },
				success : function(json){
					if(json.code === 0) {
						function getResult(obj) {
							return ['<tr>',
							    	'<td>',obj.prjId,'</td>',
							    	'<td>',obj.prjName,'</td>',
							    	'<td>',obj.createUserName,'</td>',
							    	'<td>',obj.createTime,'</td>',
							    	'<td><a class="glyphicon glyphicon-remove text-success" href="javascript:prjInfo.del(\'',obj.aiId,'\',\'',obj.prjId,'\')" title="删除"></a>',
							    	'&nbsp;&nbsp;&nbsp;<a class="text-success" href="${webroot}/prjInfo/f-view/edit?prjId=',obj.prjId,'" title="查看服务详情">查看</a>',
							    	'</td>',
								'</tr>'].join('');
						}
						prjInfoPage.operate(json.body, { resultFn:getResult, dataNull:'没有记录噢' });
					}
					else alert(JUtil.msg.ajaxErr);
				}
			});
		},
		add: function() {
			var prjId = $('#prjId');
			if (JUtil.isEmpty(prjId.val())) {
				message('请选择要添加的服务');
				return;
			}
			JUtil.ajax({
				url: '${webroot}/appInfo/f-json/savePrj',
				data: {
					aiId: $('#aiId').val(),
					prjId: prjId.val()
				},
				success : function(json) {
					if (json.code === 0) {
						setTimeout(function() {
							prjInfo.loadInfo();
						}, 800);
					}
					else if (json.code === -1)
						message(JUtil.msg.ajaxErr);
					else
						message(json.message);
				}
			});
		},
		del: function(aiId, prjId) {
			if(confirm('您确定要删除该记录吗?')) {
				JUtil.ajax({
					url: '${webroot}/appInfo/f-json/deletePrj',
					data: {
						aiId: aiId,
						prjId: prjId
					},
					success : function(json) {
						if (json.code === 0) {
							setTimeout(function() {
								prjInfo.loadInfo();
							}, 800);
						}
						else if (json.code === -1)
							message(JUtil.msg.ajaxErr);
						else
							message(json.message);
					}
				});
			}
		}
};

var userInfoPage = undefined;
var userInfo = {
		init: function() {
			userInfo.loadInfo(1);
		},
		loadInfo : function(page) {
			if(!userInfoPage) {
				userInfoPage = new Page('userInfoPage', userInfo.loadInfo, 'userInfoPanel', 'userInfoPage');
				userInfoPage.beginString = ['<table class="table table-striped table-hover"><thead><tr class="info">',
				                         '<th>角色</th>',
				                         '<th>用户名称</th>',
				                         '<th>关联人</th>',
				                         '<th width="150">关联时间</th>',
				                         '<th width="80">操作</th>',
				                         '</tr></thead><tbody>'].join('');
				userInfoPage.endString = '</tbody></table>';
			}
			if(page != undefined)
				userInfoPage.page = page;

			JUtil.ajax({
				url : '${webroot}/appInfo/f-json/pageQueryUser',
				data : { page:userInfoPage.page, size:userInfoPage.size, aiId: $('#aiId').val() },
				beforeSend: function(){ userInfoPage.beforeSend('加载信息中...'); },
				error : function(json){ userInfoPage.error('加载信息出错了!'); },
				success : function(json){
					if(json.code === 0) {
						function getResult(obj) {
							return ['<tr>',
							    	'<td>',obj.userRoleName,'</td>',
							    	'<td>',obj.userName,'</td>',
							    	'<td>',obj.createUserName,'</td>',
							    	'<td>',obj.createTime,'</td>',
							    	'<td><a class="glyphicon glyphicon-remove text-success" href="javascript:userInfo.del(\'',obj.aiId,'\',\'',obj.userId,'\')" title="删除"></a>',
							    	'</td>',
								'</tr>'].join('');
						}
						userInfoPage.operate(json.body, { resultFn:getResult, dataNull:'没有记录噢' });
					}
					else alert(JUtil.msg.ajaxErr);
				}
			});
		},
		add: function() {
			var userId = $('#userId');
			if (JUtil.isEmpty(userId.val())) {
				message('请选择要添加的用户');
				return;
			}
			JUtil.ajax({
				url: '${webroot}/appInfo/f-json/saveUser',
				data: {
					aiId: $('#aiId').val(),
					userId: userId.val()
				},
				success : function(json) {
					if (json.code === 0) {
						setTimeout(function() {
							userInfo.loadInfo();
						}, 800);
					}
					else if (json.code === -1)
						message(JUtil.msg.ajaxErr);
					else
						message(json.message);
				}
			});
		},
		del: function(aiId,userId) {
			if(confirm('您确定要删除该记录吗?')) {
				JUtil.ajax({
					url: '${webroot}/appInfo/f-json/deleteUser',
					data: {
						aiId: aiId,
						userId: userId
					},
					success : function(json) {
						if (json.code === 0) {
							setTimeout(function() {
								userInfo.loadInfo();
							}, 800);
						}
						else if (json.code === -1)
							message(JUtil.msg.ajaxErr);
						else
							message(json.message);
					}
				});
			}
		}
};

$(function() {
	var tab = '${param.tab}';
	if (tab != '') {
		${param.tab}Info.init();
	}
	JUtil.sys.typeahead({
		id: 'prjName',
		valueId: 'prjId',
		url: webroot + '/prjInfo/f-json/findSearch'
	});
	JUtil.sys.typeahead({
		id: 'userName',
		valueId: 'userId',
		url: webroot + '/sysUser/f-json/findSearch'
	});
	$('#saveBtn').click(function() {
		var saveMsg = $('#saveMsg').empty();
		var code = $('#code');
		if(JUtil.isEmpty(code.val())) {
			saveMsg.append('请输入用户编码');
			code.focus();
			return;
		}
		
		var name = $('#name');
		if(JUtil.isEmpty(name.val())) {
			saveMsg.append('请输入名称');
			name.focus();
			return;
		}

		JUtil.ajax({
			eventId: 'saveBtn',
			url: '${webroot}/appInfo/f-json/save',
			data: {
				aiId: $('#aiId').val(),
				code: code.val(),
				name: name.val(),
				phone: $('#phone').val(),
				remark: $('#remark').val()
			},
			success : function(json) {
				if (json.code === 0) {
					saveMsg.attr('class', 'label label-success').append('保存成功');
					setTimeout(function() {
						parent.info.loadInfo();
						parent.dialog.close();
					}, 800);
				}
				else if (json.code === -1)
					saveMsg.append(JUtil.msg.ajaxErr);
				else
					saveMsg.append(json.message);
			}
		});
	});
});
</script>
</body>
</html>